<gm:page title="Trends Watcher" authenticate="false">

    <script type="text/javascript" src="http://code.jquery.com/jquery.js"> </script>
    <link rel="stylesheet" href="http://jquery.com/demo/thickbox/thickbox-code/thickbox.css" type="text/css" media="screen" />
    <script>
        $(document).ready(function(){
            $("#myTable").addClass("blue-theme");
            $("#myFeedTable").addClass("blue-theme");
            $("#myWikiTable").addClass("blue-theme");
        });
    </script>

     <div>
        <font size="40" color="#B5B5B5">
            <b> Google Trends Watcher </b>
        </font>
    </div>
    <gm:list id="myTrendList" data="http://pipes.yahoo.com/pipes/pipe.run?_id=db085ae4acd2723e50dea3ec15b7e9c3&_render=rss" pagesize="10" template="myTrendTemplate">
        <gm:handleEvent src="myTrendItemEvent" event="select" execute="getGNews(event.entry)"/><gm:handleEvent src="myTrendItemEvent" event="repaint" execute="init();"/>
    </gm:list>
    <br/>
    <gm:template id="myTrendTemplate">
        <table border="1" class="black-theme">
            <tr>
                <td repeat="true">
                    <b><gm:text ref="atom:title"/></b>
                </td>
                <td align="center">
                    <gm:pager/>
                </td>
            </tr>
        </table>
    </gm:template>
    <script>
        
        /** 
         * This Method is loaded on initialization. Preliminary trend list would be populated with the initial data from the feed.
         *
         **/
        function init(){
            var myfList = google.mashups.getObjectById('myTrendList');
            getGNews(myfList.getData().entryAt(0));
            
        }
        
        /** 
         * This Method dynamically builds a table for a given Feed name, List name and Table Name
         *
         **/
        function buildTable(feedname, listname, tablename){
            var titleGPath = new GPath('atom:title');
            var summaryGPath = new GPath('atom:summary');
            var titleLinkGPath = new GPath('atom:link/@href');
            
            var myList = google.mashups.getObjectById(listname);
            var myTable = document.getElementById(tablename);
            myTable.innerHTML = '';
            var newHead = document.createElement('thead');
            var newHeadRow = document.createElement('tr');
            var newHeadCell = document.createElement('th');
            newHeadCell.innerHTML = '<b>' + feedname + '</b>';
            newHeadRow.appendChild(newHeadCell);
            newHead.appendChild(newHeadRow);
            myTable.appendChild(newHead);
            var newRow = document.createElement('tr');
            
            for (var i = 0; i < myList.getData().size(); i++) {
                var entry = myList.getData().entryAt(i);
                
                var newCell = document.createElement('td');
                if (i % 2 == 0) {
                    newCell.setAttribute('bgcolor', '#ccddee');
                }
                newCell.innerHTML = '<b><a href="' + titleLinkGPath.getValue(entry) + '?TB_iframe=true&height=600&width=900" title="' + titleGPath.getValue(entry) + '" class="thickbox">' + titleGPath.getValue(entry) + '</a></b><br/>';
                newCell.innerHTML += summaryGPath.getValue(entry);
                newRow.appendChild(newCell);
                
                myTable.appendChild(newRow);
                newRow = document.createElement('tr');
                
            }
        }
        
  /** 
         * This Method fetches information from a data provider as a rss feed
         *
         **/        
        function getGNews(entry){

            if (entry) {
                var urlGPath = new GPath("atom:title");
                var urlString = urlGPath.getValue(entry);
                var newsurl = "http://news.google.com/news?hl=en&ned=&";
                var newssearchstr = urlString;
                var
suburl =
"&ie=UTF-8&nolr=1&output=rss&ned=:ePkh8BM9E2IRYipIFeJxYkvKLy7Jz_NY9MFAiBVorwELiMoDUgi7gQLFEAEk24U0uISdSosz81KLixWM9AwUXPJzEzPzgJqUGLR4kGVAdqXmwFxrJGB0b98fhR_n9m351PRty33HiF9sQOlfbKw5-cmJQJq5KDUZABJ2K_M";
                newsurl = newsurl + "q=" + newssearchstr + suburl;
                var feedurl = "http://www.google.com/blogsearch_feeds?hl=en&q=" + newssearchstr + "&ie=utf-8&num=10&output=rss";
                var wikiurl = "http://pipes.yahoo.com/pipes/pipe.run?_id=ff40fb4903b29933d05984eec84b38df&_render=rss&input=" + newssearchstr;
                google.mashups.getObjectById('myList').setData(newsurl);
                google.mashups.getObjectById('myFeedList').setData(feedurl);
                google.mashups.getObjectById('myWikiList').setData(wikiurl);
                
            }
            
        }
        
    </script>
    <script type="text/javascript">
        <!--
        google_ad_client = "pub-5547013892989028";
        /* 728x15, created 11/6/08 */
        google_ad_slot = "9199442661";
        google_ad_width = 728;
        google_ad_height = 15;
        //-->
    </script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <br/>
    <br/>
    <table>
        <tr valign="top">
            <td style="padding-right:15px" valign="top" width="300">
                <gm:list id="myList" data="http://news.google.com/news?hl=en&ned=&q=palin&ie=UTF-8&nolr=1&output=rss&ned=:ePkh8BM9E2IRYipIFeJxYkvKLy7Jz_NY9MFAiBVorwELiMoDUgi7gQLFEAEk24U0uISdSosz81KLixWM9AwUXPJzEzPzgJqUGLR4kGVAdqXmwFxrJGB0b98fhR_n9m351PRty33HiF9sQOlfbKw5-cmJQJq5KDUZABJ2K_M" pagesize="10" style="display:none">
                    <gm:handleEvent event="repaint" execute="buildTable('Blog Search','myList','myTable')" />
                </gm:list>
                <table id="myTable">
                </table>
            </td>
            <td style="padding-right:15px" valign="top" width="300">
                <gm:list id="myFeedList" data="http://www.google.com/blogsearch_feeds?hl=en&q=palin&ie=utf-8&num=10&output=rss" pagesize="10" style="display:none">
                    <gm:handleEvent event="repaint" execute="buildTable('News Search','myFeedList','myFeedTable')" />
                </gm:list>
                <table id="myFeedTable">
                </table>
            </td>
            <td style="padding-right:10px; width:250px" valign="top">
                <gm:list id="myWikiList" data="http://pipes.yahoo.com/pipes/pipe.run?_id=ff40fb4903b29933d05984eec84b38df&_render=rss&input=Palin" pagesize="10" style="display:none">
                    <gm:handleEvent event="repaint" execute="buildTable('Wiki Search','myWikiList','myWikiTable')" />
                </gm:list>
                <table id="myWikiTable">
                </table>
            </td>
            
            <td>
              <gm:list id="myWikiList1" data="http://bfads.net/news.xml" pagesize="10">
                </gm:list>

              
              </td>
            <td>
                <script type="text/javascript">
                    <!--
                    google_ad_client = "pub-5547013892989028";
                    /* 160x600, created 11/11/08 */
                    google_ad_slot = "7273881629";
                    google_ad_width = 160;
                    google_ad_height = 600;
                    //-->
                </script>
                <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>
            </td>
        </tr>
    </table>
    <script type="text/javascript" src="http://jquery.com/demo/thickbox/thickbox-code/thickbox.js">
    </script>
    <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
        var pageTracker = _gat._getTracker("UA-6157391-3");
        pageTracker._trackPageview();
    </script>
</gm:page>

